class friend_vm
  constructor: (inits) ->
     @name = ko.observable ""
     @selected = ko.observable false  

class window.pick_friends_vm
  constructor: (@parent) ->    
    @friends = ko.observableArray []
    @selectedFriends = ko.computed =>
      ko.utils.arrayFilter(
        @friends(),
        (friend) =>
          friend.selected() is true
      )
    
    window.setTimeout =>  
      @_Create_Friends()
    , 250
    
  _Create_Friends: =>
    underlying_array = @friends()
    underlying_array.push new friend_vm() for n in [1..8]
    underlying_array[0].name 'Ron Burgundy'    
    underlying_array[1].name 'Chet McFinnigan'
    underlying_array[2].name 'Mike Wazowski'
    underlying_array[3].name 'Jean-Luc Picard'
    underlying_array[4].name 'Brick Hardmeat'
    underlying_array[5].name 'Big McLargeHuge'
    underlying_array[6].name 'Fist Gibson'
    underlying_array[7].name 'Ricky Flash'
    
    @friends.valueHasMutated()
  
  Tap_Friend: (d,e) =>
    d.selected(true)
        
  Submit_Friends_List: (d,e) =>
     #TODO: Submit to REST service and go to some result page
     $('#friendsDialog').popup("open")
         
  Navigate: (d,e) =>
     $('#friendsDialog').popup("close")
     @parent.Navigate Templates.OPTIONS